let s:abbreviations = {
            \'cs': 'csquotes',
            \'fl': 'float',
            \'gr': 'graphicx',
            \'mi': 'minted',
            \'si': 'siunitx',
            \'su': 'subcaption',
            \'ti': 'tikz',
            \'ur': 'url',
            \}

function import#tex#add(name) abort
    let name = s:abbreviations->get(a:name, a:name)
    let options = ''
    let match = name->matchlist('\(\[.*\]\)\(.*\)')
    if match != []
        let options = match[1]
        let name = match[2]
    endif
    let position = getcurpos()[1:]
    let position[0] += 1
    let firstlinenum = 1
    for line in getline(1, 8)
        if line =~# '^\\usepackage\>' && line !~# '{inputenc}' && line !~# '{babel}'
            break
        endif
        let firstlinenum += 1
    endfor
    if firstlinenum > 8
        let firstlinenum = 1
    endif
    execute 'normal! '.firstlinenum.'GO\usepackage'.options.'{'.name."}\<esc>"
    let lastlinenum = firstlinenum
    while getline(lastlinenum + 1) =~# '^\\usepackage\>'
        let lastlinenum += 1
    endwhile
    execute firstlinenum.','.lastlinenum.'sort r /\]\?{\w*}/'
    call cursor(position)
endfunction
